<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <title>订单编辑</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}"/>
</head>
<body>

<form class="layui-form">
    <blockquote class="layui-elem-quote">编辑</blockquote>

    <div class="layui-form-item">
        <label class="layui-form-label">订单编号：</label>
        <div class="layui-input-inline">
            <input type="text" id="o_Id" name="o_Id" readonly  autocomplete="off" class="layui-input" style="width: 300px;">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">商品标题：</label>
        <div class="layui-input-inline">
            <input type="text" id="p_Title" name="p_Title" readonly  autocomplete="off" class="layui-input" style="width: 300px;">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">卖家ID：</label>
        <div class="layui-input-inline">
            <input type="text" id="o_Seller" name="o_Seller" readonly  autocomplete="off" class="layui-input" style="width: 300px;">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">收货地址：</label>
        <div class="layui-input-inline">
            <select name="o_Baddress" id="o_Baddress" lay-verify="required" lay-filter="xmFilter">
                <option value="请选择" style="width: 300px;"></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-form-label">
            <button lay-submit lay-filter="AddressUpdate" type="button" class="layui-btn">保存</button>
        </div>
    </div>
</form>

<script th:src="@{/layui/layui.js}"></script>
<script th:src="@{/layui/jquery.min.js}"></script>
<script>
    layui.use(['element','form','layer','table'], function(){
       const form = layui.form;
       const $ = layui.$;
       const table = layui.table;
        $.ajax({  // select框ajax动态赋值
            url: 'selectValue',
            type: 'POST',
            contentType: "application/json;charset=utf-8",
            success: function (res) {
                const field = res.data;
                $.each(field, function (index, item) {  // $.each表示对JavaScript中数组对象的遍历，函数第一个参数为下标，第二个参数为下标对应的值
                    $('#o_Baddress').append(new Option(item));// 下拉菜单里添加元素
                });
                form.render("select");
            }
        });

        form.on('submit(AddressUpdate)',function (data){
            const field = data.field;
            console.log(field);
            $.ajax({
                url: 'orderChange',
                type: 'POST',
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify(field),
                success: function (res){
                    if(res.code === 200){
                        layer.msg(res.msg);
                        window.setTimeout('parent.layer.closeAll()', 3000);
                    }else if(res.code === 500){
                        layer.msg(res.msg);
                    }
                },
                error: function (res){
                    layer.msg('请求错误！');
                }
            });
        });
    })
</script>
<script>
    function toBuyOrder(){ <!-- 转跳 -->
        window.location.href = '/admin/BuyOrderInit';
    }
</script>
</body>
</html>